<script setup lang="ts">
import { onMounted } from 'vue';
import { getCurrentInstance } from '@tarojs/taro';
import { LOGIN_APP } from '/@/api/modules/base/app-sys-user';
import { GENERATE_TOKEN } from '/@/api/modules/open-api/auth';
/**
 * @description 当前路由信息
 */
const params = getCurrentInstance().router?.params as unknown as {
  clientId: string;
  from: string;
};

onMounted(() => {
  LOGIN_APP({}).then((res) => {
    GENERATE_TOKEN({ clientId: params.clientId, uaaUserId: res.sysUserDto.uaaUserId }).then(
      (res) => {
        //江南公安
        if (params.clientId === 'asset_cloud') {
          window.location.replace(`${params.from}?token=${res.token}&tenantId=jhjnga`);
        } else {
          if (params.clientId) {
            window.location.replace(`${params.from}?token=${res.token}`);
          } else {
            window.location.replace(`${params.from}`);
          }
        }
      },
    );
  });
});
</script>

<template>
  <view class="app-page--1">
    <nut-toast msg="加载中" :visible="true" type="loading" :cover="true" />
  </view>
</template>
